package com.ssyc.gsk_teacher.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ssyc.common.adapter.CommonAdapter;
import com.ssyc.common.adapter.ViewHolder;
import com.ssyc.common.glide.ImageUtil;
import com.ssyc.common.view.XCRoundRectImageView;
import com.ssyc.gsk_teacher.R;
import com.ssyc.gsk_teacher.bean.WorkInfo;

import java.util.List;

/**
 * 教师端--班级学生列表
 * Created by Kevin on 2018/6/30
 */

public class WorkSutdentGvAdapter extends CommonAdapter<WorkInfo.ListBean> {

    private Context context;

    public WorkSutdentGvAdapter(Context context, List<WorkInfo.ListBean> datas, int layoutId) {
        super(context, datas, layoutId);
        this.context = context;
    }

    @Override
    public void convert(ViewHolder holder, final WorkInfo.ListBean listBean) {
        //头像
        XCRoundRectImageView lvHead = holder.getView(R.id.lv_head);
        if(!TextUtils.isEmpty(listBean.getIcon())){
            ImageUtil.displayImage(context,lvHead,listBean.getIcon(),R.drawable.base_default_head);
        }

        //名称
        TextView tvName = holder.getView(R.id.tv_name);
        tvName.setText(listBean.getName());
        //外层选中
        LinearLayout llOut = holder.getView(R.id.ll_out);

        //状态
        ImageView lvState = holder.getView(R.id.lv_delete);

        RelativeLayout rl_img_bg = holder.getView(R.id.rl_img_bg);
        //根据选中状态设置选中状态的值
        if (!listBean.flag) {
            lvState.setVisibility(View.VISIBLE);
            lvState.setImageResource(R.drawable.teacher_st_select);
            rl_img_bg.setBackgroundResource(R.drawable.teacher_rl_stu_bg);
        } else {
            lvState.setVisibility(View.INVISIBLE);
            rl_img_bg.setBackgroundResource(R.color.transparent);
        }
        llOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listBean.flag = !listBean.flag;
                notifyDataSetChanged();
            }
        });
    }
}
